// pages/jubao/jubao.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items: [
      { name: '0', value: '不实信息'},
      { name: '1', value: '有害信息'},
      { name: '2', value: '人身攻击' },
      { name: '3', value: '违法信息' },
      { name: '4', value: '垃圾信息' },
      { name: '5', value: '淫秽色情' },
      { name: '6', value: '其他' }
    ],
    value: '',
    num: 0,
    id:0,
    number:"",
    name:"",
    nickName:wx.getStorageSync('nickName')
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    this.setData({
      number: e.detail.value
    })
  },
  inputs(e) {
    console.log(e.detail.value)
    var value = e.detail.value;
    var num = parseInt(value.length);
    this.setData({
      num: num,
      value: value 
       });
  },
  jubao(e){
    var that = this;
    let openid = wx.getStorageSync('openid');
    let authorization = wx.getStorageSync('authorization');
    let url = wx.getStorageSync('url');
    var a = that.data.number
    if(a !=""){
      a = a.join(',')
    }
    wx.request({
      url: url + "/v1/article/report",
      data: {
        articleId: that.data.id,
        description:that.data.value,
        opt: a
      },
      method: "post",
      header: {
        'content-type': 'application/json',
        'authorization': authorization,
        'openid': wx.getStorageSync('openid')
      },
      success: function (res) {
        wx.showToast({
          title: "举报成功",
          icon: 'success',
          duration: 1000
        })
        var item =[
          { name: '0', value: '不实信息' ,checked:false},
          { name: '1', value: '有害信息', checked: false},
          { name: '2', value: '人身攻击', checked: false},
          { name: '3', value: '违法信息', checked: false},
          { name: '4', value: '垃圾信息', checked: false },
          { name: '5', value: '淫秽色情', checked: false},
          { name: '6', value: '其他', checked: false}
        ];
        that.setData({
          value:"",
          number:0,
          num:0,
          items:item,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
      this.setData({
        id:options.id,
        name:options.name
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})